#drafted by Jeremy VanDerWal ( jjvanderwal@gmail.com ... www.jjvanderwal.com )
#GNU General Public License .. feel free to use / distribute ... no warranties

################################################################################
###load the necessary libraries
library(SDMTools) 

#directory locations
work.dir = 'D:/Barra Work Directory/craig/' #define the directory with monthly tmin/tmax
setwd(work.dir)

################################################################################

#01.load the data
tdata = read.csv ('Query40.csv')

png(paste(work.dir, 'craig.test.png',sep=''), width=14, height=14, units='cm', res=300, pointsize=5, bg='white')
par(mfrow=c(2,2), mar=c(5,5,2,2), oma=c(1,1,1,1))

				
mat = matrix(c(1,1,2,3,3,3,
				1,1,1,3,3,3,
				1,1,1,3,3,3,
				4,4,4,5,5,5,
				4,4,4,5,5,5,
				4,4,4,5,5,5),nr=6,nc=6,byrow=TRUE)
layout(mat) #call layout as defined above

plot(tdata$dem80,tdata$bc01, xlab='Elevation (m)', ylab='Annual mean temperature', type='n', cex.lab=2, cex.axis=1.6, font.lab='2')
points(tdata$dem80[which(tdata$Subregion=="AU")], tdata$bc01[which(tdata$Subregion=="AU")], pch=19, col='red')
points(tdata$dem80[which(tdata$Subregion=="CU")], tdata$bc01[which(tdata$Subregion=="CU")], pch=19, col='blue')
points(tdata$dem80[which(tdata$Subregion=="SU")], tdata$bc01[which(tdata$Subregion=="SU")], pch=19, col='green')

par(mar=c(0,2,2,2))
plot(0,0, ylim=c(0,1), xlim=c(0,1), axes=FALSE, ann=FALSE, type='n')
legend(0,1, c('Atherton','Carbine', 'Paluma'), fill=c('red','blue','green'), title='Subregion', cex=2, bty='n')	

par(mar=c(5,5,2,2))
plot(tdata$dem80,tdata$bc04, xlab='Elevation (m)', ylab='Temperature seasonality', type='n', cex.lab=2, cex.axis=1.6, font.lab='2')
points(tdata$dem80[which(tdata$Subregion=="AU")], tdata$bc04[which(tdata$Subregion=="AU")], pch=19, col='red')
points(tdata$dem80[which(tdata$Subregion=="CU")], tdata$bc04[which(tdata$Subregion=="CU")], pch=19, col='blue')
points(tdata$dem80[which(tdata$Subregion=="SU")], tdata$bc04[which(tdata$Subregion=="SU")], pch=19, col='green')

plot(tdata$dem80,tdata$bc12, xlab='Elevation (m)', ylab='Annual precipitation', type='n', cex.lab=2, cex.axis=1.6, font.lab='2')
points(tdata$dem80[which(tdata$Subregion=="AU")], tdata$bc12[which(tdata$Subregion=="AU")], pch=19, col='red')
points(tdata$dem80[which(tdata$Subregion=="CU")], tdata$bc12[which(tdata$Subregion=="CU")], pch=19, col='blue')
points(tdata$dem80[which(tdata$Subregion=="SU")], tdata$bc12[which(tdata$Subregion=="SU")], pch=19, col='green')

plot(tdata$dem80,tdata$bc15, xlab='Elevation (m)', ylab='Precipitation seasonality', type='n', cex.lab=2, cex.axis=1.6, font.lab='2')
points(tdata$dem80[which(tdata$Subregion=="AU")], tdata$bc15[which(tdata$Subregion=="AU")], pch=19, col='red')
points(tdata$dem80[which(tdata$Subregion=="CU")], tdata$bc15[which(tdata$Subregion=="CU")], pch=19, col='blue')
points(tdata$dem80[which(tdata$Subregion=="SU")], tdata$bc15[which(tdata$Subregion=="SU")], pch=19, col='green')

dev.off()
